import Vue from "vue";
import PortalVue from "portal-vue";
import ElementUI from "element-ui";
import VXETable from "vxe-table";
// import Diamond from '@yiducloud/epidemic-diamond'
import App from "./App.vue";
import store from "./store";
import router from "./router";
import service from "./service";

// import '@yiducloud/theme-yidu/index.scss'
// import '@yiducloud/yidu-ui/lib/packages/theme-yidu/index.scss'
import "element-ui/lib/theme-chalk/index.css";
import "@/style/global.scss";
import "@/style/vxe.scss";
import "@/icon/style.css";
import "leaflet/dist/leaflet.css";

import { loginAppid, serviceApp, ROOT_PATH } from "./app-config";

import "./views/risk/icons";

Vue.use(PortalVue);
Vue.use(ElementUI);

VXETable.setup({ zIndex: 3000, table: {} });
Vue.use(VXETable);

Vue.use(service);

function init(app = "", id = "") {
  // 登录
  // Vue.use(Diamond, {
  //     store,
  //     router,
  //     serviceApp: app || serviceApp,
  //     loginAppid: id || loginAppid,
  //     systemApi: `${ROOT_PATH}/rbac`,
  //     purview: 'login',
  // })

  // render
  new Vue({
    router,
    store,
    render: (h) => h(App),
  }).$mount("#app");

  // 获取页面配置
  // store.dispatch('getPageConfig')
}

Vue.config.productionTip = false;
window.EVENTBUS = new Vue({});

// 获取应用appId
// Vue.http.get(`/api/monitor_warning/version/get_service_app_id`).then(({ body }) => {
//     const appId = body.data
//     const lastIndex = appId.lastIndexOf('_')
//     const array = lastIndex !== -1 ? [appId.slice(0, lastIndex), appId.slice(lastIndex + 1)] : [appId, '']
//     init(array[0], array[1])
// }).catch(error => {
//     console.log(error, 'error')
//     init()
// })

init();

if (process.env.NODE_ENV !== "production") {
  // fetch("https://proxy-auth.yiducloud.cn/sso/cookies").then((result) => {
  //   result.json().then((data) => {
  //     window.document.cookie = `nginx_proxy_session=${data.nginx_proxy_session};`;
  //   });
  // });
}
